package com.yuanxuzhen.ffmpeg;


import android.app.Activity;
import android.content.Context;
import android.os.Environment;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.io.File;


public class MainActivity extends Activity {

    static {
        System.loadLibrary("native-lib");
    }

    private TextView mTextView;
    private YuanVideoView mVideoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTextView = findViewById(R.id.sample_text);
        mVideoView = findViewById(R.id.videoView);
    }

    public void onButtonClick(View view) {
        int id = view.getId();
        String videoPath = getCacheDir(this) + File.separator + "cut.mp4";

        switch (id) {
            /*
            case R.id.button_protocol:
                setInfoText(FFUtils.urlProtocolInfo());
                break;
            case R.id.button_codec:
                setInfoText(FFUtils.avCodecInfo());
                break;
            case R.id.button_filter:
                setInfoText(FFUtils.avFilterInfo());
                break;
            case R.id.button_format:
                setInfoText(FFUtils.avFormatInfo());
                break;
                */
            case R.id.button_play:
                //String videoPath = Environment.getExternalStorageDirectory() + "/Movies/PERU.MP4";

                mVideoView.playVideo(videoPath);
                break;
            case R.id.button_open_gl_play:
                //String videoPath = Environment.getExternalStorageDirectory() + "/Movies/PERU.MP4";

                mVideoView.playOpenGlVideo(videoPath);
                break;
        }
    }

    private void setInfoText(String content) {
        if (mTextView != null) {
            mTextView.setText(content);
        }
    }


    public static String getCacheDir(Context context) {
        String path = null;
        if (context.getExternalCacheDir() != null
                && (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
                || !Environment.isExternalStorageRemovable())) {
            //外部存储可用
            path = context.getExternalCacheDir().getPath();
        } else {
            //内部存储不可用
            path = context.getCacheDir().getPath();
        }
        Log.e("yuanxzh", path);
        return path;
    }
}
